import axios from "axios";
import { ElMessage } from "element-plus";


const request = axios.create({
    // 请求基础路径设置
    baseURL: '/api',
    // 超时时间设置,超过5秒就是失败的
    timeout: 5000,
})

//请求拦截器
request.interceptors.request.use(config => {
    // config 请求拦截器回调注入对象，配置对象的headers属性
    console.log('config', config)
    return config;
})

//响应拦截截器


request.interceptors.response.use(response => {
    console.log("response", response);

    return response;
}, (error) => {
    console.log("error", error);

    let status = error.response.status;

    switch (status) {

        case 404:
            ElMessage({
                type: 'error',
                message: '404 Not Found'
            })
    }


    return Promise.reject(new Error(error.message))
})



//对外暴露 axios
export default request;


